﻿/* Copyright 2010 Igor Francé
 * 
 * This file is part of ECMADoc (http://ecmadoc.codeplex.com).
 * 
 * ECMADoc is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License 
 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
 * 
 * ECMADoc is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with ECMADoc. 
 * If not, see http://www.gnu.org/licenses/.
 */
namespace EcmaDoc.Core
{
	using System;
	using System.Linq;

	/// <summary>
	/// Event arguments supplied with each <see cref="Project.ProcessProgress"/> event.
	/// </summary>
	public class ProjectOperationProgressEventArgs : EventArgs
	{
		private readonly ProjectOperation operation;

		/// <summary>
		/// Initializes a new instance of the <see cref="ProjectOperationProgressEventArgs"/> class.
		/// </summary>
		/// <param name="projectName">The name of the project associated with this event.</param>
		/// <param name="operation">The project operation associated with this event.</param>
		public ProjectOperationProgressEventArgs(string projectName, ProjectOperation operation)
		{
			this.operation = operation;
			this.ProjectName = projectName;
			this.StepIndex = 0;
		}

		/// <summary>
		/// Gets a value indicating whether the operation is complete.
		/// </summary>
		/// <value><c>true</c> if complete; otherwise, <c>false</c>.</value>
		public bool Complete { get; internal set; }

		/// <summary>
		/// Gets the index of the current operation's step.
		/// </summary>
		public int StepIndex { get; internal set; }

		/// <summary>
		/// Gets the number (1-based index) of the operation step from the <see cref="ProjectOperation"/> associated 
		/// with this event.
		/// </summary>
		public int StepNumber
		{ 
			get
			{
				return StepIndex + 1;
			}
		}

		/// <summary>
		/// Gets the number of steps in the <see cref="ProjectOperation"/> associated with this event.
		/// </summary>
		public int StepCount 
		{
			get
			{
				return this.operation.Steps.Count;
			}
		}

		/// <summary>
		/// Gets the name of the <see cref="ProjectOperation"/> associated with this event.
		/// </summary>
		public string OperationName
		{
			get
			{
				return this.operation.Name;
			}
		}

		/// <summary>
		/// Gets the name of the object currently operated on.
		/// </summary>
		public string ObjectName { get; internal set; }

		/// <summary>
		/// Gets name of the project associated with this event.
		/// </summary>
		public string ProjectName { get; private set; }

		/// <summary>
		/// Gets the name of cur project associated with this event.
		/// </summary>
		public string CurrentStepName
		{
			get
			{
				return operation.Steps.Keys.ToList<string>()[StepIndex];
			}
		}

		/// <summary>
		/// Gets the percent complete for the complete processing of a whole project.
		/// </summary>
		public int PercentDoneOperationTotal
		{
			get
			{
				// lets assume each operation taken the same amount of time:
				float chunk = 100F / StepCount;

				float result = (StepIndex * chunk) + (PercentDoneOperationStep * (chunk / 100F));
				return result > 100 ? 100 : Convert.ToInt32(result);
			}
		}

		/// <summary>
		/// Gets the percent complete for the current operation (file discovery, generating output, etc).
		/// </summary>
		public int PercentDoneOperationStep { get; internal set; }

		/// <summary>
		/// Gets the percent complete for the current step (parsing a single file, etc).
		/// </summary>
		public int PercentDoneCurrentFile { get; internal set; }
	}
}
